package core.hxl.service;

import core.hxl.stream.MessageObject;
import core.hxl.stream.MessageStreams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

@Service
@EnableBinding(MessageStreams.class)
public class MessageProducer {

    @Autowired
    MessageStreams messageStreams;

    public void sendMessage(MessageObject messageObject){
        try {
            System.out.println("Producer Message: mess=>"+messageObject.getMess()+" time=>"+messageObject.getTime());
            messageStreams.sendMessage().send(MessageBuilder.withPayload(messageObject).build());
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
